package com.hongxun.project.assets.kHgq.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hongxun.framework.aspectj.lang.annotation.Log;
import com.hongxun.framework.aspectj.lang.enums.BusinessType;
import com.hongxun.project.assets.kHgq.domain.KHgq;
import com.hongxun.project.assets.kHgq.service.IKHgqService;
import com.hongxun.framework.web.controller.BaseController;
import com.hongxun.framework.web.page.TableDataInfo;
import com.hongxun.framework.web.domain.AjaxResult;
import com.hongxun.common.utils.poi.ExcelUtil;

/**
 * 互感器-扩展 信息操作处理
 * 
 * @author hongxun
 * @date 2019-06-13
 */
@Controller
@RequestMapping("/assets/kHgq")
public class KHgqController extends BaseController
{
    private String prefix = "assets/kHgq";
	
	@Autowired
	private IKHgqService kHgqService;
	
	@RequiresPermissions("assets:kHgq:view")
	@GetMapping()
	public String kHgq()
	{
	    return prefix + "/kHgq";
	}
	
	/**
	 * 查询互感器-扩展列表
	 */
	@RequiresPermissions("assets:kHgq:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(KHgq kHgq)
	{
		startPage();
        List<KHgq> list = kHgqService.selectKHgqList(kHgq);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出互感器-扩展列表
	 */
	@RequiresPermissions("assets:kHgq:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KHgq kHgq)
    {
    	List<KHgq> list = kHgqService.selectKHgqList(kHgq);
        ExcelUtil<KHgq> util = new ExcelUtil<KHgq>(KHgq.class);
        return util.exportExcel(list, "kHgq");
    }
	
	/**
	 * 新增互感器-扩展
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存互感器-扩展
	 */
	@RequiresPermissions("assets:kHgq:add")
	@Log(title = "互感器-扩展", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(KHgq kHgq)
	{		
		return toAjax(kHgqService.insertKHgq(kHgq));
	}

	@GetMapping("/addForDeviceId")
	public String addForDeviceId(KHgq kHgq , ModelMap modelMap)
	{
		modelMap.put("newByqId",kHgq.getByqId());
		modelMap.put("newPointId",kHgq.getPId());
		modelMap.put("newDeviceId",kHgq.getDeviceId());
		return prefix + "/addForDeviceId";
	}

	/**
	 * 修改互感器-扩展
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		KHgq kHgq = kHgqService.selectKHgqById(id);
		mmap.put("kHgq", kHgq);
	    return prefix + "/edit";
	}

	//	修改低压电流互感器
	@GetMapping("/editForDeviceId/{id}")
	public String editForDeviceId(@PathVariable("id") String id, ModelMap mmap)
	{
		KHgq kHgq = new KHgq();
		kHgq.setDeviceId(id);
		List<KHgq> kHgqList = kHgqService.selectKHgqList(kHgq);
		mmap.put("kHgq", kHgqList.get(0));
	    return prefix + "/editForDeviceId";
	}
	
	/**
	 * 修改保存互感器-扩展
	 */
	@RequiresPermissions("assets:kHgq:edit")
	@Log(title = "互感器-扩展", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(KHgq kHgq)
	{		
		return toAjax(kHgqService.updateKHgq(kHgq));
	}
	
	/**
	 * 删除互感器-扩展
	 */
	@RequiresPermissions("assets:kHgq:remove")
	@Log(title = "互感器-扩展", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(kHgqService.deleteKHgqByIds(ids));
	}
	
}
